// pages/goods_provide/index.js
var app = getApp(); //引用app.js
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var commonURLXX = app.data.lastURL;
var baseURL1 = app.data.baseURL;
var jielong = app.data.jielong;
var jlpay = app.data.jlpay
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  getname:function(e){
    this.setData({
      name:e.detail.value
    })
  },
  getphone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    wx.getStorage({
      key: 'userInfo',
      success: function(res) {
        that.setData({
          userInfo:res.data,

        })
      },
    })
    wx.request({
      url: commonURL+'op=return',
      data:{
        uniacid: app.data.GZHid,
        unionId: app.data.unionId || wx.getStorageSync('unionId'),
        openid:wx.getStorageSync('openid')
      },
      success:function(res){
        console.log(res)
        that.setData({
          data:res.data,
          name: res.data.name,
          phone: res.data.mobile
        })
      }
    })
  },
  formSubmit: function () {
    var formObj = this.data;
    var list = [];
    if (formObj.name == '') {
      wx.showToast({
        title: '姓名不能为空！',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    if (!(/^1[34578]\d{9}$/.test(formObj.phone))) {
      wx.showToast({
        title: '手机号输入有误！',
        icon: 'none',
        duration: 4000
      })
      return false;
    }
    var tem={
      name: formObj.name,
      mobile: formObj.phone,
      uniacid: app.data.GZHid,
      openid:wx.getStorageSync('openid'),
      write:1
    }
    wx.request({
      url: commonURL + 'op=return',
      data: tem,
      success: function (res) {
        console.log(res)
        if(res.data.status==1){
          wx.showModal({
            title: '提示',
            content: '修改成功',
            showCancel: false,
            complete: function (res) {
              wx.redirectTo({
                url: '../user/user',
              })
            }
          })
        }else{
          wx.showToast({
            title: res.data.msg,
          })
        }
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})